package com.gumball.states;

import java.util.Random;

import com.gumball.context.GumballMachine;

public class HasQuarterState implements State {
	private Random randomWinner = new Random(System.currentTimeMillis());

	private GumballMachine gumballMachine;

	public HasQuarterState(GumballMachine gumballMachine) {
		this.gumballMachine = gumballMachine;
	}

	@Override
	public void insertQuater() {
		System.out.println("You can't insert another quarter");
	}

	@Override
	public void ejectQuater() {
		System.out.println("Quarter returned");

	}

	@Override
	public void turnCrank() {
		System.out.println("You turned...");
		int winner = randomWinner.nextInt(10);
		if((winner == 0) && (gumballMachine.getCount() > 1)) {
			gumballMachine.setState(gumballMachine.getWinnerState());
		} else {
			gumballMachine.setState(gumballMachine.getSoldState());
		}
		
	}

	@Override
	public void dispense() {
		System.out.println("No gumball dispensed");

	}

}
